package com.flyqiu.flow.api.script;



import javax.el.ELContext;
import javax.el.ELResolver;
import java.beans.FeatureDescriptor;
import java.util.Iterator;

public class ProcJuelVariableResolver extends ELResolver {
    private IVariableScope variableScope;

    public ProcJuelVariableResolver(IVariableScope variableScope) {
        this.variableScope = variableScope;
    }

    @Override
    public Class<?> getCommonPropertyType(ELContext context, Object base) {
        return null;
    }

    @Override
    public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
        return null;
    }

    @Override
    public Class<?> getType(ELContext context, Object base, Object property) {
        return null;
    }

    @Override
    public Object getValue(ELContext context, Object base, Object property) {
        if (!(property instanceof String prop)) {
            return null;
        }
        if (variableScope.hasVar(prop)) {
            context.setPropertyResolved(true);
            return variableScope.getVal(prop);
        }
        return null;
    }

    @Override
    public boolean isReadOnly(ELContext context, Object base, Object property) {
        if (base != null) return false;
        return !variableScope.hasVar((String) property);
    }

    @Override
    public void setValue(ELContext context, Object base, Object property, Object value) {

    }
}
